home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / malloc15.zip / MEM.H < prev    next >
C/C++ Source or Header  |  1996-04-17  |  3KB  |  96 lines

  1. #ifndef _MEM_H
  2. #define _MEM_H
  3. /*
  4.  * mem.h:
  5.  *      Includes for Nigel Horne's malloc wrap around for C. All output is
  6.  * via stderr.
  7.  *      To use just link the required object file into your application.
  8.  * For the best results you should include this file (mem.h) in each source
  9.  * file and recompile
  10.  *
  11.  * Version 1.5.
  12.  *
  13.  * DOS:
  14.  *      Suitable for MSC8.00c (a.k.a. MSVC 1.5)
  15.  * usage: cl /AS test.c dosmems.obj /link /noe
  16.  *
  17.  * SCO Unix:
  18.  * Contains mem.o which you should link with your application,
  19.  * and mem.h which you can optionally include in each .c file. This would be
  20.  * the best action as then mem.o will be better at finding which file has
  21.  * gone wrong. The included test.c shows some common problems. To test all
  22.  * is well I suggest you try "cc test.c mem.o -link -z" and see look at the
  23.  * output. Do not link with the shared library "-lc_s" option, as this will
  24.  * cause conflicts with the library.
  25.  *
  26.  * HP\UX:
  27.  * As SCO Unix.
  28.  *
  29.  * AIX:
  30.  *    You do not want builtins. Use
  31.  *    cc -O2 -roconst -U__STR__ -qlanglvl=ansi *.c
  32.  *
  33.  * Internet: njh@smsltd.demon.co.uk; Fidonet: Nigel Horne @ 2:2502/21.10;
  34.  * Packet: G0LOV@GB7SYP.#19.GBR.EDU; Phone: +44-1226-283021.
  35.  */
  36. #include <stdio.h>
  37. #include <assert.h>
  38. #include <malloc.h>
  39. #include <memory.h>
  40. #include <string.h>
  41. #ifdef  MSDOS
  42. #include <conio.h>
  43. #endif
  44. #include <limits.h>
  45. #include <stdlib.h>
  46. #ifndef sun
  47. #include <stdarg.h>
  48. #endif
  49.  
  50. #pragma function(memset, memcpy, memcmp, strcmp, strcpy, strcat)
  51.  
  52. typedef enum { false = 0, true = 1 } bool;
  53.  
  54. #define malloc(s)       db_mallocchk(s, __FILE__, __LINE__)
  55. #define calloc(n, s)    db_callocchk(n, s, __FILE__, __LINE__)
  56. #define realloc(o, s)   db_reallocchk(o, s, __FILE__, __LINE__)
  57. #define strdup(s)       db_strdupchk(s, __FILE__, __LINE__)
  58. #define free(s) db_freechk(s, __FILE__, __LINE__)
  59. #define heapchk()       db_heapchk(__FILE__, __LINE__)
  60.  
  61. #ifdef  __GNUC__
  62. #define pascal
  63. #define cdecl
  64. #define _pascal
  65. #define _cdecl
  66. #endif
  67.  
  68. #if     defined(_unix) && !defined(unix)
  69. #define unix
  70. #endif
  71.  
  72. #if     !defined(MSDOS) && !defined(M_XENIX)
  73. #define _cdecl
  74. #define cdecl
  75. #define _pascal
  76. #define pascal
  77. #endif
  78.  
  79. void    *_pascal        db_mallocchk(size_t size, const char *file, int line);
  80. void    *_pascal        db_callocchk(size_t nelem, size_t size, const char
  81. *file, int line);
  82. void    *_pascal        db_reallocchk(void *oarea, size_t size, const char
  83. *file, int line);
  84. char    *_pascal        db_strdupchk(const char *string, const char *file,
  85. int line);
  86. void    _pascal db_freechk(void *memblock, const char *file, int line);
  87. void    _pascal db_heapchk(const char *file, int line);
  88.  
  89. #ifndef sun
  90. extern  bool    check_for_leaks;        /*
  91.                                          * check for memory leaks - default
  92. true
  93.                                          */
  94. #endif
  95. #endif /* _MEM_H */
  96.